#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/i2c-gpio.h>
#include <linux/i2c.h>
 
#define I2C0_SDA	20 //GPIO20
#define I2C0_SCL	19 //GPIO19
 
static struct i2c_gpio_platform_data gpio_i2c_bus_data = {
	.sda_pin = I2C0_SDA,
	.sda_is_open_drain = 0, //IO是否为开漏输出
	.scl_pin = I2C0_SCL,
	.scl_is_open_drain = 0,
	.udelay = 2,
	.timeout = 100,
};
 
static struct platform_device gpio_i2c_bus_device = {
	.name = "i2c-gpio", // 名称必须是这个
	.id = 0, // 编号不能与现有的I2C总线冲突
	.dev.platform_data = &gpio_i2c_bus_data,
};
 
static int __init gpio_i2c_bus_device_init(void)
{
	platform_device_register(&gpio_i2c_bus_device); //注册上去，就完事了
 
	return 0;  
}
 
static void __exit gpio_i2c_bus_device_exit(void)
{
	platform_device_unregister(&gpio_i2c_bus_device);
}
 
module_init(gpio_i2c_bus_device_init);
module_exit(gpio_i2c_bus_device_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Yuyaowen");